package registryx

import (
	"context"

	triple_greet "dubbox/triple/proto/triple"

	"dubbo.apache.org/dubbo-go/v3/client"
	_ "dubbo.apache.org/dubbo-go/v3/imports"
	health "dubbo.apache.org/dubbo-go/v3/protocol/triple/health/triple_health"
	"github.com/dubbogo/gost/log/logger"
)

func Health(cli *client.Client) {
	svc, err := health.NewHealth(cli)
	if err != nil {
		panic(err)
	}
	h := &health.HealthCheckRequest{Service: triple_greet.GreetService_ClientInfo.InterfaceName}
	check, err := svc.Check(context.Background(), h)
	if err != nil {
		logger.Error(err)
	} else {
		logger.Info("greet.GreetService's health", check.String())
	}
	watch, err := svc.Watch(context.Background(), h)
	if err != nil {
		logger.Error(err)
	} else {
		if watch.Recv() {
			logger.Info("greet.GreetService's health", watch.Msg().String())
		}
	}

}
